package com.cogent.business.action.base;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import org.apache.struts2.ServletActionContext;

import com.cogent.business.action.AbstractAction;
import com.cogent.business.helper.MenuHelper;
import com.cogent.common.util.MapUtil;
import com.cogent.menu.domain.MenuDomain;

public class MainAction extends AbstractAction {
	
	public String noright() {
		return "noright";
	}
	
	public String view() {
		if(getUserInfo() == null)
			return "noright";
		return "view";
	}
	
	public String getsub() {
		List list = new ArrayList();
		if(getUserInfo() == null) {
			HashMap map = new HashMap();
			map.put("resourcepath", "noright.action");	
			list.add(map);
		} else {
			HashMap formMap = getFormMapWithUser();
			String key = MapUtil.getStringValue(formMap, "menukey");
			List sublist = MenuHelper.getThridMenu(ServletActionContext.getRequest(), key);
			Iterator it = sublist.iterator();
			while(it.hasNext()) {
				MenuDomain menudomain = (MenuDomain)it.next();
				HashMap map = new HashMap();
				map.put("resourcepath", menudomain.getResourcepath());
				map.put("resourcecode", menudomain.getResourcecode());
				map.put("resourcename", menudomain.getResourcename());
				map.put("levels", menudomain.getLevels());
				list.add(map);
			}
		}
		String message = MapUtil.listMapToJsonStr(list);
		responseMsg(message);
		
		return null;
	}
}
